<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - AI公众号助手</title>
    <link rel="stylesheet" href="/styles.css">
</head>
<body>
    <div class="container">
        <div class="login-container">
            <div class="login-box">
                <a href="/" class="back-home">← 返回首页</a>
                <h2>欢迎登录</h2>
                <p class="login-subtitle">AI公众号助手</p>
                <form id="loginForm" class="login-form">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" id="username" name="username" placeholder="请输入用户名" required>
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" id="password" name="password" placeholder="请输入密码" required>
                    </div>
                    <div class="form-options">
                        <label class="remember-me">
                            <input type="checkbox" id="remember" name="remember">
                            <span>记住我</span>
                        </label>
                        <a href="#" class="forgot-password">忘记密码？</a>
                    </div>
                    <button type="submit" class="login-submit-btn">登录</button>
                    <div class="register-link">
                        <span>还没有账号？</span>
                        <a href="/register" class="register-btn">立即注册</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            
            // 发送登录请求
            fetch('/user/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: new URLSearchParams({
                    username: username,
                    password: password
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 登录成功，跳转到首页
                    window.location.href = '/';
                } else {
                    // 登录失败，显示错误信息
                    alert(data.message);
                }
            })
            .catch(error => {
                console.error('登录请求失败:', error);
                alert('登录请求失败，请稍后重试');
            });
        });
    </script>
</body>
</html> 